const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class CommunityProfileHandler extends BaseHandler {

    get pattern() {
        return '/community/:community_id/profile';
    }

    doGET(request,response) {
        var wallId = request.params.community_id;
        var wallUserId = request.session.walls[wallId].wall_user_id;
        this.Controller.getWallUserProfileWithAssets(wallUserId, (result) => {
            response.json(result);
        });
    }

    doPOST(request, response) {
        var wallUserId = request.session.walls[request.params.community_id].wall_user_id;
        this.Controller.updateWallUserProfile(wallUserId, request.body, (result) => {
            request.session.walls[request.params.community_id].is_anonymous = false;
            response.json(result);
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.POST, this.doPOST);
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = CommunityProfileHandler;